The Traveling Salesman Problem (TSP) and Hamiltonian Path/Cycle problems are closely related, but they are not the same thing.
In a travelling salesman problem with 8 cities, the goal is to find the shortest possible route that starts at City A, visits each of the remaining seven cities exactly once, and returns to City A.
The number of possible directed tours is given by:
P(n) = (n − 1)!
For eight cities:
P(8) = 7! = 5040
In an undirected TSP, a route and its reverse direction represent the same path. To remove these duplicates, the number of unique tours is:
U(n) = (n − 1)! / 2
For eight cities:
U(8) = 7! / 2 = 2520
This means there are 2520 unique undirected tours when reverse paths are treated as identical.
Click any cell to edit its weight. Use 1e9 to mark a forbidden transition.